<script setup>
import { onMounted, ref } from "vue";
import { useRouter } from "vue-router";

import store from "../../store";
// store.changetype(window.localStorage.getItem("policytype"));
store.sendVolunteer();
const router = useRouter();
var goBack = function () {
  window.location.replace("../Home/Home.html");
};

function skipBack() {
  // window.history.back(1);
  location.replace("../Home/Home.html");
  console.log(2);
}

function skipDetail(index) {
  localStorage.setItem("index_2", index);
}

function searchQuery() {
  store.sendVolunteer2().then((val) => {
    console.log("data", val);
    dataArr.value = val.data.filter((item) => {
      return item.name.includes(keyWord.value);
    });
  });
}

const keyWord = ref("");

const dataArr = ref([]);

onMounted(() => {
  store.sendVolunteer2().then((val) => {
    dataArr.value = val.data;

    console.log("vvvvvv", dataArr.value);
  });
});
</script>

<template>
  <div>
    <div class="back" @click="goBack">
      <img style="width: 20px" src="../../assets/箭头-左.png" alt="" />
    </div>
    <div class="titou">学业辅导中心</div>
    <header>
      <input class="search" v-model="keyWord" type="text" />
      <div class="search-logo" @click="searchQuery">
        <img style="width: 20px" src="../../assets/sousuo.png" alt="" />
      </div>
    </header>
    <main>
      <ul>
        <a
          href="../volunteerDetail/volunteer.html"
          class="li-wrap"
          @click="skipDetail(index)"
          v-for="(item, index) in dataArr"
          :key="item"
        >
          <li class="item">
            {{ item.name }}
            <div class="shuyuan">({{ item.insit }})</div>
          </li>
          <div class="item-r">{{ item.subject }}</div>
        </a>
      </ul>
    </main>
  </div>
</template>

<style scoped>
* {
  margin: 0;
  padding: 0;
}

a {
  text-decoration: none;
  color: black;
}

body {
  max-width: 100%;
  overflow-x: hidden;
}

header {
  /* background-color: brown; */
  line-height: 60px;
  position: relative;
}

.search {
  width: 100%;
  box-sizing: border-box;
}

.titou {
  position: absolute;
  top: 12px;
  font-size: 16px;
  color: #414141;
  left: calc(50% - 48px);
}

input {
  outline: none;
  border: 1px solid brown;
  box-shadow: none;
  background: none;
  line-height: 30px;
  border-radius: 8px;
  color: brown;
  padding-left: 10px;
}

main {
  padding: 20px 10px;
  /* background-color: #44BE87; */
  background: url("../../../public/bgp.png");
  background-size: 100%;
  margin-top: 10px;
  border-radius: 8px;
}

.item {
  font-size: 18px;
  line-height: 1.7;
  padding: 4px;
  box-sizing: border-box;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
}

.item > .shuyuan {
  font-size: 10px;
  display: inline-block;
  color: #6b6b6b;
}

.item-r {
  padding: 4px;
  color: #414141;
  padding-left: 40px;
}

.li-wrap {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
  background-color: white;
  box-sizing: border-box;
  margin-top: 10px;
  list-style-type: disc;
  padding: 0 10px;
  border-radius: 3px;
  height: 70px;
}

.search-logo {
  position: absolute;
  top: 50%;
  transform: translateY(-40%);
  right: 20px;
}

.back {
  width: 30px;
  height: 30px;
  border-radius: 4px;
  background-color: brown;
  text-align: center;
  overflow: hidden;
}

.back > img {
  margin-top: 5px;
}
</style>
